<template>
  <div class="it-page it-auth">
    <it-header title="登陆" :from="false" :showAvatar="false">
    </it-header>
    <div class="container-fluid am-text-xs">
      <div class="login-page">
        <div class="login-top">
          <img :src="img" alt="">
          <p class="register" @click.stop.prevent="goToRegister">立即注册,手机打卡</p>
        </div>
        <div class="login-panel">
          <form id="login-form" class="login-form">
            <div class="input-group">
              <span class="input-group-addon">
                <i class="fa fa-envelope" aria-hidden="true"></i>
              </span>
              <input type="text" class="form-control" placeholder="邮箱" name="email" autocomplete="off" v-model="email" />
            </div>
            <div class="input-group" v-if="curDemand === 1">
              <span class="input-group-addon">
                <i class="fa fa-mobile" aria-hidden="true"></i>
              </span>
              <input type="text" class="form-control" placeholder="手机号" name="mobile" autocomplete="off" v-model="mobile" />
            </div>
            <div class="input-group" v-if="curDemand === 1">
              <span class="input-group-addon">
                <i class="fa fa-user" aria-hidden="true"></i>
              </span>
              <input type="text" class="form-control" placeholder="用户名" name="name" autocomplete="off" v-model="username" />
            </div>
            <div class="input-group">
              <span class="input-group-addon">
                <i class="fa fa-lock" aria-hidden="true"></i>
              </span>
              <input type="password" class="form-control" placeholder="密码" name="password" autocomplete="off" v-model="password" />
            </div>
            <!-- <div class="input-group" v-if="needCaptchaCode">
              <span class="input-group-addon">
                                <i class="fa fa-key" aria-hidden="true"></i>
                            </span>
              <input type="text" class="form-control" placeholder="验证码" name="captchaCode" v-model="model.captchaCode" />
              <span class="input-group-addon captcha-code">
                                <img :src="codeImageSrc">
                            </span>
            </div> -->
            <div class="message-panel"></div>
            <button v-if="curDemand === 1" type="button" class="button submit" @click="register">注册</button>
            <button v-else type="button" class="button submit" @click="login">登录</button>
            <!-- <p class="actions">
              <router-link :to="getPageUrl('register')" class="pull-left">注册
              </router-link>
              <router-link :to="getPageUrl('reset-pwd')" class="pull-right">忘记密码</router-link>
            </p> -->
          </form>
          <!-- <form id="register-form" style="display: none;">
            <div class="input-group">
              <span class="input-group-addon">
                                <i class="fa fa-mobile" aria-hidden="true"></i>
                            </span>
              <input v-if="!isSupportUserNameLogin" type="text" class="form-control" placeholder="手机号" name="mobile" v-model="model.mobile" autocomplete="off" />
              <input v-if="isSupportUserNameLogin" type="text" class="form-control" placeholder="用户名" name="mobile" v-model="model.mobile" autocomplete="off" />
            </div>
            <div class="input-group">
              <span class="input-group-addon">
                                <i class="fa fa-unlock-alt" aria-hidden="true"></i>
                            </span>
              <input type="password" class="form-control" placeholder="密码" name="password" v-model="model.password" autocomplete="off" />
            </div>
            <div class="input-group">
              <span class="input-group-addon">
                                <i class="fa fa-lock" aria-hidden="true"></i>
                            </span>
              <input type="password" class="form-control" placeholder="确认密码" name="confirm" v-model="model.password2" autocomplete="off" />
            </div>
            <div class="input-group" v-if="!hideInvitedCode">
              <span class="input-group-addon">
                                <i class="fa fa-male" aria-hidden="true"></i>
                            </span>
              <input type="text" class="form-control it-lowercase" placeholder="邀请码" name="invitedCode" v-model="model.invitedCode" autocomplete="off" />
            </div>
            <div class="input-group">
              <span class="input-group-addon">
                                <i class="fa fa-key" aria-hidden="true"></i>
                            </span>
              <input type="text" class="form-control" placeholder="验证码" name="checkCode" v-model="model.checkCode" />
              <span class="input-group-addon">
                                <button class="btn button send-code" type="button"
                                        @click.stop.prevent="getSmsCode(1)">点击发送</button>
                            </span>
            </div>
            <div class="form-group">
              <div class="checkbox text-left">
                <label>
                  <input type="checkbox" name="agreement" v-model="model.agreement" />我已阅读并同意<span class="text-danger"><a href="javascript: void 0;"
                                                       @click.stop.prevent="onRisktip">《风险提醒》</a></span>
                </label>
              </div>
            </div>
            <div class="message-panel"></div>
            <button type="button" class="button submit" @click.stop.prevent="registerUser" v-if="isRegisterEnabled">注册
            </button>
            <p class="actions">
              <router-link :to="getPageUrl('login')" class="pull-left">登录</router-link>
              <router-link :to="getPageUrl('reset-pwd')" class="pull-right">忘记密码</router-link>
            </p>
          </form> -->
          <!-- <form id="reset-pwd-form" style="display: none;">
            <div class="input-group" v-if="!isLoginIn">
              <span class="input-group-addon">
                                <i class="fa fa-mobile" aria-hidden="true"></i>
                            </span>
              <input v-if="!isSupportUserNameLogin" type="text" class="form-control" placeholder="手机号" name="mobile" v-model="model.mobile" autocomplete="off" />
              <input v-if="isSupportUserNameLogin" type="text" class="form-control" placeholder="用户名" name="mobile" v-model="model.mobile" autocomplete="off" />
            </div>
            <div class="input-group">
              <span class="input-group-addon">
                                <i class="fa fa-unlock-alt" aria-hidden="true"></i>
                            </span>
              <input type="password" class="form-control" placeholder="新密码" name="password" v-model="model.password" autocomplete="off" />
            </div>
            <div class="input-group">
              <span class="input-group-addon">
                                <i class="fa fa-lock" aria-hidden="true"></i>
                            </span>
              <input type="password" class="form-control" placeholder="确认密码" name="confirm" v-model="model.password2" autocomplete="off" />
            </div>
            <div class="input-group">
              <span class="input-group-addon">
                                <i class="fa fa-key" aria-hidden="true"></i>
                            </span>
              <input type="text" class="form-control" placeholder="验证码" name="checkCode" v-model="model.checkCode" />
              <span class="input-group-addon">
                                <button class="btn button send-code" type="button"
                                        @click.stop.prevent="getSmsCode(2)">点击发送</button>
                            </span>
            </div>
            <div class="message-panel"></div>
            <button type="button" class="button submit" @click.stop.prevent="resetPwd">重置
            </button>
            <p class="actions" v-if="isActionLinkShow">
              <router-link :to="getPageUrl('register')" class="pull-left" v-if="isRegisterEnabled">注册
              </router-link>
              <router-link :to="getPageUrl('login')" class="pull-right">登录</router-link>
            </p>
          </form> -->
          <!-- <form id="agent-form" style="display: none;">
            <div class="input-group">
              <span class="input-group-addon">
                                <i class="fa fa-user" aria-hidden="true"></i>
                            </span>
              <input type="text" class="form-control" placeholder="经纪人名称" name="userName" v-model="model.brokerName" autocomplete="off" />
            </div>
            <div class="input-group">
              <span class="input-group-addon">
                                <i class="fa fa-key" aria-hidden="true"></i>
                            </span>
              <input type="text" class="form-control" placeholder="验证码" name="checkCode_agent" v-model="model.brokerCheck" />
              <span class="input-group-addon">
                                <button class="btn button send-code" type="button"
                                        @click.stop.prevent="getSmsCode(3)"
                                >获取验证码</button>
                            </span>
            </div>
            <div class="message-panel"></div>
            <button type="button" class="button submit" @click.stop.prevent="applyBroker">提交
            </button>
          </form> -->
          <!-- <form id="update-pwd-form" style="display: none;">
            <div class="input-group">
              <span class="input-group-addon">
                                <i class="fa fa-unlock" aria-hidden="true"></i>
                            </span>
              <input type="password" class="form-control" name="password" placeholder="旧密码" v-model="model.password">
            </div>
            <div class="input-group">
              <span class="input-group-addon">
                                <i class="fa fa-unlock-alt" aria-hidden="true"></i>
                            </span>
              <input type="password" class="form-control" name="newPassword" placeholder="新密码" v-model="model.newPassword">
            </div>
            <div class="input-group">
              <span class="input-group-addon">
                                <i class="fa fa-lock" aria-hidden="true"></i>
                            </span>
              <input type="password" class="form-control" name="password2" placeholder="确认新密码" v-model="model.password2">
            </div>
            <div class="message-panel"></div>
            <button id="update-btn" type="button" class="button submit" @click.stop.prevent="updatePwd">修改
            </button>
          </form> -->
          <!-- <form id="reset-trade-pwd-form" style="display: none;">
            <div class="input-group">
              <span class="input-group-addon">
                                <i class="fa fa-unlock-alt" aria-hidden="true"></i>
                            </span>
              <input type="password" class="form-control" placeholder="新密码" name="password" v-model="model.password" autocomplete="off" />
            </div>
            <div class="input-group">
              <span class="input-group-addon">
                                <i class="fa fa-lock" aria-hidden="true"></i>
                            </span>
              <input type="password" class="form-control" placeholder="确认密码" name="confirm" v-model="model.password2" autocomplete="off" />
            </div>
            <div class="input-group">
              <span class="input-group-addon">
                                <i class="fa fa-key" aria-hidden="true"></i>
                            </span>
              <input type="text" class="form-control" placeholder="验证码" name="checkCode" v-model="model.checkCode" />
              <span class="input-group-addon">
                                <button class="btn button send-code" type="button"
                                        @click.stop.prevent="getSmsCode(4)">点击发送</button>
                            </span>
            </div>
            <div class="message-panel"></div>
            <button type="button" class="button submit" @click.stop.prevent="resetTradePwd">重置
            </button>
          </form> -->
        </div>
      </div>
    </div>
    <!--弹出框-->
    <!-- <mt-message-box :show="isRiskTipShow" @cancel="closeRiskTip" cancelText="关闭">
      <div class="iframe-container">
        <iframe :src="risktipUrl"></iframe>
      </div>
    </mt-message-box> -->
  </div>
</template>
<script>
import userAvatar from '../../assets/user-avatar.jpg'
import defaultAvatar from '../../assets/default-avatar.jpg'

export default {
  name: 'login',
  data() {
    return {
      curDemand: 0, // 0: 登录, 1: 注册
      img: defaultAvatar,
      password: '',
      username: '',
      mobile: '',
      email: ''
    }
  },
  methods: {
    login() {
      this.api.login({
        email: this.email,
        password: this.password
      }).then(res => {
        this.$router.go(-1)
      })
    },
    goToRegister() {
      this.curDemand = 1
    },
    register() {
      this.api.register({
        email: this.email,
        mobile: this.mobile,
        username: this.username,
        password: this.password
      }).then(res => {
        return this.api.login({
          email: this.email,
          password: this.password
        })
      }).then(res => {
        this.$router.go(-1)
      })
    }
  }
}

</script>
<style lang="scss" rel="stylesheet/scss">
$it-top-bar-height: 0.88rem;
$it-bottom-bar-height: 0.98rem;
.it-auth.it-page {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  padding-top: 80px;
  background: #FEFAFE;
  position: absolute;
  .it-header {
    background: #FE585B;
  }
  .login-top {
    text-align: center;
    img {
      width: 80px;
      height: 80px;
    }
    .register {
      margin-top: 15px;
      color: #433F43;
      text-decoration: underline;
      &:active {
        color: #ccc;
      }
    }
  }

  .container-fluid:before,
  .container-fluid:after {
    content: "";
    display: block;
    clear: both;
  }

  .login-page {
    .login-panel {
      position: relative;
      z-index: 1;
      max-width: 310px;
      margin: 0 auto 0;
      padding: 20px 30px 30px;
      text-align: center;
      .form-control {
        outline: 0;
        background: #FEFAFE;
        width: 100%;
        border: 0;
        padding: 8px 15px 8px 0;
        box-sizing: border-box;
        font-size: 14px;
        height: 40px;
        border-radius: 0;
        margin: 0;
        box-shadow: none;
      }
    }
    .fa {
      font-size: 20px;
      height: 20px;
      width: 20px;
    }
  }
  .checkbox {
    label {
      padding-left: 0;
    }
    input {
      position: inherit;
      vertical-align: bottom;
      margin-right: 5px;
      margin-left: 0;
    }
  }
  .input-group {
    position: relative;
    margin: 0 0 15px;
    border-bottom: 1px solid #F0ECF0;
  }
  .login-page .login-panel .form-control:focus {
    box-shadow: none;
  }

  .login-page .login-panel .input-group-addon {
    position: absolute;
    top: 4px;
    left: -36px;
    border-radius: 0;
    border: none;
    background-color: #FEFAFE;
    padding: 6px 8px;
    color: #ED737C;
  }

  .login-page .login-panel .button {
    text-transform: uppercase;
    outline: 0;
    background: #f97d83;
    width: 100%;
    border: 0;
    color: #f2f2f2;
    font-size: 14px;
    border-radius: 2px;
  }
  .login-page .login-panel .submit {
    height: 40px;
    margin-top: 15px;
  }
  .login-page .login-panel .button:hover,
  .login-page .login-panel .button:active,
  .login-page .login-panel .button:focus {
    background: #f97d83;
  }
  .login-page .login-panel .input-group-addon .btn {
    padding: 7px 0;
    background-color: #FE5959;
    border-radius: 0;
    width: 90px;
  }

  .login-page .login-panel .button.send-code {
    padding: 4px 0;
    height: 30px;
  }

  .login-page .login-panel .actions {
    margin: 15px 0 0;
    color: #b3b0b0;
    font-size: 12px;
  }

  .login-page .login-panel .actions a {
    color: #C3BFC3;
    text-decoration: none;
  }

  .login-page .login-panel .register-form {
    display: none;
  }

  .login-page .message-panel .message {
    padding: 5px;
    color: #f36c76;
  }

  .login-form {
    .captcha-code {
      width: 80px;
      height: 40px;
      padding: 3px 5px;
      overflow: hidden;

      img {
        width: 100%;
        height: 100%;
      }
    }
  }

  .iframe-modal {
    >.modal-dialog {
      top: #{$it-top-bar-height * 1.2};
    }
  }
  .mint-msgbox {
    height: 380px;
  }
  .mint-msgbox-content {
    height: 320px;
    .iframe-container {
      height: 100%;
      iframe {
        height: 100%;
      }
    }
  }
}

</style>
